{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=1461
  Verdict: Accepted
}
uses SysUtils, Math;
 
type
	pair=record
		c,i:longint;
	end;
 
var
	i,n,ans,kk,cc:longint;
	a,b:array[0..1010] of longint;
	tt:pair;
 
function check():pair;
var
	i,cur,first:longint;	
begin
result.c:=0;
result.i:=0;
cur:=1;
first:=1;
for i:=2 to n do begin
	if a[i]=a[first] then inc(cur);
	if (a[i]<>a[first]) or (i=n) then begin  
		if cur>2 then begin
			result.c:=cur;
			result.i:=first;
			break;
		end;
		first:=i;
		cur:=1;
	end;
end;
end;
 
begin
reset(input,'input.txt');
rewrite(output,'output.txt');
read(n);
for i:=1 to n do
	read(a[i]);
ans:=0;
tt:=check();
while tt.c>0 do begin
	kk:=tt.i+tt.c-1;
	cc:=0;
	for i:=1 to n do begin
		if (i<tt.i) or (i>kk) then begin
			inc(cc);
			b[cc]:=a[i];
		end;
	end;
	a:=b;
	inc(ans,tt.c);
	n:=cc;
	tt:=check();
end;
write(ans);
end.